package mx.ipn.presentacion.nomina;

import mx.ipn.presentacion.nomina.ui.*;
import mx.ipn.presentacion.ConexionConNegocios;
import com.trolltech.qt.gui.QMessageBox;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QTableWidgetItem;
import com.trolltech.qt.gui.QWidget;
import com.trolltech.qt.gui.QDialog;
import mx.ipn.to.*;

import java.util.*;
public class Principal extends QDialog{
	Ui_Principal p;
	ComprobantePercepcionDescuentoTO [] compro;
	double total;
	GregorianCalendar f1 = new GregorianCalendar();
	java.util.Date fechaini;
	java.util.Date fechapago;
	QTableWidgetItem newItem = null;
	public Principal(){
			p = new Ui_Principal();
			p.setupUi(this);
			//rep.tableWidget.setRowCount(1);
			//rep.tableWidget.itemClicked.connect(this,"selectFactura()");
			//rep.pushButton.clicked.connect(this, "ver()");
			p.pushButton.clicked.connect(this, "comp()");
			p.pushButton_2.clicked.connect(this, "creardesc()");
			p.pushButton_3.clicked.connect(this, "creardesc()");
			p.pushButton_4.clicked.connect(this, "asignemp()");
			p.pushButton_5.clicked.connect(this, "asignpuesto()");
			//p.pushButton_6.clicked.connect(this, "tipopd()");
			p.pushButton_7.clicked.connect(this, "buscar()");
			//rep.radioButton.clicked.connect(this,"mes()");
			//rep.radioButton_2.clicked.connect(this,"dia()");
			//ConexionConNegocios.inicializar();
			this.show();
	}
	public Principal(QDialog parent){
			
	}
	public boolean rango(java.util.Date fecha,int mes,int anio)
    {
    	boolean flag=false;
    	f1.setTime(fecha);
    	if(f1.get(GregorianCalendar.MONTH ) ==mes && f1.get(GregorianCalendar.YEAR )==anio)
    		flag=true;
    	return flag;
    }
	public void buscar(){
		f1.set(p.dateEdit.date().year(),(p.dateEdit.date().month()-1),p.dateEdit.date().day());
	    fechaini=f1.getTime();
	    f1.set(p.dateEdit_2.date().year(),(p.dateEdit_2.date().month()-1),p.dateEdit_2.date().day());
	    fechapago=f1.getTime();
		compro = (ComprobantePercepcionDescuentoTO[])ConexionConNegocios.invocaServicio("selectComprobantePercepcionDescuento",ComprobantePercepcionDescuentoTO[].class);
		if(compro!=null){
			p.tableWidget.setRowCount(compro.length);
		       for(int i=0;i<compro.length;i++)
		        	p.tableWidget.insertRow(i);
		       int i=0;
		       for(int j=0;j<compro.length;j++){
		       	if(rango(compro[j].getFechaPago(),(p.dateEdit.date().month()-1),p.dateEdit.date().year())){
		       	newItem = new QTableWidgetItem(String.valueOf(compro[j].getFechaPago()));
	    	    p.tableWidget.setItem(i,0,newItem);
	    	    newItem = new QTableWidgetItem(String.valueOf(compro[j].getSueldoBase()));
	    	    p.tableWidget.setItem(i,1,newItem);
	    	    i++;
		        }
		       }
		}
		else{System.out.println("asasas");}
	}
	public void creardesc(){
		CrearDP creardp = new CrearDP();
	}
	public void tipopd(){
		CrearTipoPD crea = new CrearTipoPD();
	}
	public void asignemp(){
		VerTablas ver = new VerTablas();
	}
	public void asignpuesto(){
		AsignarPuesto puesto= new AsignarPuesto();
	}
	public void comp(){
		Comprobante compro = new Comprobante();
	}
	public static void main(String[] args) {
		QApplication.initialize(args);
		Principal p = new Principal();
		QApplication.exec();
	}
}